﻿//FLOATBOX.JS

function vOption()
{
    this.graph='poly';
    this.filled=false;
    this.fillcolor='#FFFFFF';
    this.stroked=true;
    this.strokecolor='#FF0000';
    this.strokeweight=1;
    this.startarrow='none';
    this.endarrow='none';
    this.closed=false;
}
function vPolyline(id,parent,arrX,arrY,option)
{
    this.id=id;
    this.arrX=(arrX==null)?[]:arrX;
    this.arrY=(arrY==null)?[]:arrY;
    this.option=(option==null)?new vOption():option;
    this.graph=this.option.graph;
    this.parent=parent;
    this.shiftX=0;
    this.shiftY=0;
    this.zoom=1;
}
vPolyline.prototype=
{
    drawPolyline:function()
    {
        this.polylineElm=document.createElement('v:polyline');
        this.polylineElm.id=this.id;
        this.strokeElm=this.polylineElm.appendChild(document.createElement('v:stroke'));
        this.setStyle();
        this.parent.appendChild(this.polylineElm);
        this.paint();
    }
    ,setOption:function(option)
    {
        if(option==null) return;
        this.option=option;
        this.setStyle();
    }
    ,setStyle:function()
    {
        this.polylineElm.stroked=this.option.stroked;
        this.polylineElm.strokecolor=this.option.strokecolor;
        this.polylineElm.strokeweight=this.option.strokeweight;
        this.polylineElm.filled=this.option.filled;
        this.polylineElm.fillcolor=this.option.fillcolor;
        if(this.startarrow!='none'||this.endarrow!='none')
        {
            this.strokeElm.startarrow=this.option.startarrow;
            this.strokeElm.endarrow=this.option.endarrow;
        }
    }
    ,addPoint:function(x,y,doPaint,index)
    {
        if(!index) index=this.arrY.length;
        else
        {
            if(index!=this.arrX.length)
            {
                for(var i=this.arrX.length-1;i>=index;i--)
                {
                    this.arrX[i+1]=this.arrX[i];
                    this.arrY[i+1]=this.arrY[i];
                }
            }
        }
        this.arrX[index]=x;
        this.arrY[index]=y;
        if(doPaint) this.paint();
    }
    ,addPoints:function(x,y,doPaint)
    {
        for(var i=0;i<x.length;i++)
        {
            this.arrX[this.arrX.length]=x[i];
            this.arrY[this.arrY.length]=y[i];
        }
        if(doPaint) this.paint();
    }
    ,setPoint:function(x,y,doPaint,index)
    {
        index=(index!=null&&index<=this.arrX.length)?index:this.arrX.length>0?this.arrX.length-1:0;
        this.arrX[index]=x;
        this.arrY[index]=y;
        if(doPaint) this.paint();
    }
    ,setPoints:function(x,y,doPaint)
    {
        this.arrX=x;
        this.arrY=y;
        if(doPaint) this.paint();
    }
    ,delPoint:function(index)
    {
        if(index<0||index>=this.arrX.length) return;
        this.arrX.splice(index,1);
        this.arrY.splice(index,1);
        this.paint();
    }
    ,paint:function()
    {
        var str='';
        for(var i=0;i<this.arrX.length;i++)
        {
            if(i>0) str+=',';
            str+=(this.arrX[i]-this.shiftX)*this.zoom+','+(this.arrY[i]-this.shiftY)*this.zoom;
        }
        if(this.option.closed)
        {
            if(str) str+=',';
            str+=(this.arrX[0]-this.shiftX)*this.zoom+','+(this.arrY[0]-this.shiftY)*this.zoom;
        }
        this.polylineElm.points.value=str;
    }
    ,setZoom:function(z)
    {
        this.zoom=z;
    }
    ,setShift:function(x,y)
    {
        this.shiftX=parseInt(x);
        this.shiftY=parseInt(y);
    }
    ,setXY:function()
    {
    }
    ,getPointNum:function()
    {
        return this.arrX.length;
    }
    ,getObj:function()
    {
        return this.polylineElm;
    }
    ,destroy:function()
    {
        this.parent.removeChild(this.polylineElm);
    }
};